package shira.seminar;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import shira.person.Educative;
import shira.person.Ken;
import shira.person.Ken.KenType;
import shira.person.Person.Gender;
import shira.seminar.Camp;
import shira.seminar.Hug;
import shira.seminar.deviations.AbstractDeviation;
import shira.sort.SortingScore;

/**
 * Tests for the {@link Hug} class.
 * 
 * @author avian
 */
public class HugTest {

	/* --- Test Methods --- */

	/**
	 * Setup for the tests.
	 */
	@Before
	public void setUp() {
		testedHug = new Hug();
	}

	/**
	 * Tests a basic score calculation.
	 */
	@Test
	public void testScoreCalculation() {
		Camp campMock = mock(Camp.class);
		when(campMock.calculateMahozScore(any(SortingScore.class))).thenReturn(
				0);
		testedHug.setCamp(campMock);
		List<Educative> educatives = new ArrayList<Educative>();
		Educative educative = new Educative();
		educative.setGender(Gender.MALE);
		Ken ken = new Ken();
		ken.setKenType(KenType.KIBUTZ);
		educative.setKen(ken);
		educatives.add(educative);
		testedHug.setEducatives(educatives);

		SortingScore score = new SortingScore(1, 2, 1, 1, 1, 1);
		int calculatedScore = testedHug.calculateScore(score);
		assertEquals(6, calculatedScore);
		verify(campMock).calculateMahozScore(score);
	}

	/**
	 * Tests the deviation calculation.
	 */
	@Test
	public void testDeviationsCalculation() {
		Educative educative = mock(Educative.class);
		when(educative.getGender()).thenReturn(Gender.MALE);
		testedHug.addEducative(educative);
		DeviationsStatistics statistics = new DeviationsStatistics();
		statistics.setExpectedMalePercentage(0);
		statistics.setAllowedMaleDeviation(0);
		List<AbstractDeviation> deviations = testedHug
				.calculateDeviations(statistics);
		assertEquals(1, deviations.size());
		verify(educative).getGender();
	}

	/* --- Data Members --- */

	/** The hug under test. */
	Hug testedHug;

}
